local json = require "cjson"

local M = {}

local S2CPlayInput_send = false
function M:send_packet(packet_name, packet_data, exclude_player_ids)
    if self:is_robot() then
        return
    end

    local agent = self:get_agent()
    if not agent then
        return
    end

    if type(exclude_player_ids) == "table" then
        for _, playerId in ipairs(exclude_player_ids) do
            if playerId == self then
                return
            end
        end
    elseif type(exclude_player_ids) == "number" then
        local playerId = exclude_player_ids
        if playerId == self then
            return
        end
    end
    --[[
    print("send_packet packet:", packet_name, " user_id:", self:get_id(), " user_name: ", self:get_user_name())
    if packet_name ~= "tunnel.forward" then
        if (packet_name == "tanker.S2CPlayInput" and not S2CPlayInput_send) or packet_name ~= "tanker.S2CPlayInput" then
            if (packet_name == "tanker.S2CPlayInput") then
                S2CPlayInput_send = true
            end
            print("packet_name", packet_name, "data:",json.encode(packet_data))
        end
    end
    --]]
    return USER_D:send_packet(agent:get_gate_channel(), agent:get_id(), packet_name, packet_data)
end

function M:process_command(MsgType, MsgData)
    return COMMAND_D:process_command(self, MsgType, MsgData)
end

F_CHAR_COMM = M
